package Classes.GameDatas // ActionScript file
{
	import Classes.GameUtils.GU_DataTransform;
	import Classes.GameViews.GV_Map;
	import Classes.GameViews.ViewDisplayers.MapTargets.MT_Building_Sundry;
	import Classes.GameViews.ViewImgs.CartoonViewImg;
	import Classes.Interfaces.GV_hot;
	import Classes.Managers.M_ConfigData;
	
	import flash.geom.Point;

	/**
	 *杂物数据类
	 * @author upstream
	 *
	 */
	public class GD_Building_Sundry extends GD_Building
	{
		private static var _sundriesConfigObj:Object;

		private var _sundryConfigObj:Object;
		private var _sundryType:Number;
		private var _serverID:Number;
		private var _view:MT_Building_Sundry;
		private var _coordinate:Number;
		private var _map:GD_Map;
		private var _sundryDur:int;
		private var _mirrorPar:int;

		public function GD_Building_Sundry(sundryType:Number):void
		{
			this._sundryType=sundryType;
			this.init();
		}

		private function init():void
		{
			this._sundryConfigObj=sundriesConfigObj[this.sundryType];
		}

		/**
		 *创建一个杂物对象
		 * @param creatObj 创建数据对象
		 * @return 杂物对象
		 *
		 */
		public static function creat(creatObj:Object, map:GD_Map=null):GD_Building_Sundry
		{
			var creatTarget:GD_Building_Sundry=new GD_Building_Sundry(creatObj.sundryType);
			creatTarget._map=map;
			if (creatObj.sundryID)
				creatTarget._serverID=creatObj.sundryID;
			if (creatObj.coordinate)
				creatTarget._coordinate=creatObj.coordinate;
			if (creatObj.sundryDur)
				creatTarget._sundryDur=creatObj.sundryDur;
			creatTarget.mirrorPar=int(creatObj.forward);
			return creatTarget;
		}

		/*getter & setter*/
		public static function get sundriesConfigObj():Object
		{
			if (!_sundriesConfigObj)
			{
				_sundriesConfigObj=new Object;
				var sundriesConfigStr:String=M_ConfigData.instance.getCSVByName("杂物配置表");
				var sundiresConfigAry:Array=GU_DataTransform.csvTransformObjsAry(sundriesConfigStr, 11);
				for each (var sundryConfigObj:Object in sundiresConfigAry)
				{
					_sundriesConfigObj[sundryConfigObj.zt_other_id]=sundryConfigObj;
				}
			}
			return _sundriesConfigObj;
		}
		
		public function get zt_other_type():Number
		{
			return this.sundryConfigObj.zt_other_type; 
		}

		/**
		 * 包含了所有杂物静态数据的OBJ
		 * @return
		 *
		 */
		public function get sundryConfigObj():Object
		{
			return _sundryConfigObj;
		}

		public function get serverID():Number
		{
			return _serverID;
		}

		public function get view():MT_Building_Sundry
		{
			if (!this._view)
			{
				_view=MT_Building_Sundry.creat(this);
//				if(this.mirrorPar==1)
//				{
//					_view.scaleX=-1;
//				}
			}
			return _view;
		}

		override public function get coordinate():Number
		{
			return _coordinate;
		}

		/**
		 * 杂物图片所在的SWf容器
		 * @return
		 *
		 */
		override public function get buildingPicSourceStr():String
		{
			return this.sundryConfigObj.zt_item_source;
		}

		/**
		 * 此杂物的第1张图片（血量为最多的）
		 * @return
		 *
		 */
		public function get sundryPic1SourceStr():String
		{
			return this.sundryConfigObj.zt_item_pic_1;
		}

		/**
		 * 此杂物的第2张图片（血量为中等的）
		 * @return
		 *
		 */
		public function get sundryPic2SourceStr():String
		{
			return this.sundryConfigObj.zt_item_pic_2;
		}

		/**
		 * 此杂物的第3张图片（血量为最少的）
		 * @return
		 *
		 */
		public function get sundryPic3SourceStr():String
		{
			return this.sundryConfigObj.zt_item_pic_3;
		}

		/**
		 * 杂物最大血量
		 * @return
		 *
		 */
		public function get sundryDurMax():int
		{
			return this.sundryConfigObj.zt_other_blood;
		}

		/**
		 * 杂物名字
		 * @return
		 *
		 */
		public function get sundryName():String
		{
			return this.sundryConfigObj.zt_other_name;
		}

		/**
		 * 杂物ID
		 * @return
		 *
		 */
		public function get sundryType():Number
		{
			return _sundryType;
		}

		/**
		 * 类型（300平面310立体）
		 * @return
		 */
		public function get otherType():Number
		{
			return this.sundryConfigObj.zt_item_type;
		}

		/**
		 *  描述
		 * @return
		 */
		public function get description():String
		{
			return this.sundryConfigObj.zt_other_desc;
		}

		/**
		 * 建筑占地面积
		 * @return
		 */
		override public function get size():int
		{
			return this.sundryConfigObj.zt_func_size_num;
		}

		/**
		 * 根据血量算出来的图片
		 * @return
		 */
		override public function get buildingPicStr():String
		{
			var pro:Number=this.sundryDur / this.sundryDurMax;
			if (pro > 2 / 3)
			{
				return this.sundryPic1SourceStr;
			}
			else if (pro > 1 / 3)
			{
				return this.sundryPic2SourceStr;
			}
			else
			{
				return this.sundryPic3SourceStr;
			}
			return "";
		}

		public function get positionPoint():Point
		{
			var atx:int=this.coordinate % this.map.widthNum;
			var aty:int=int(this.coordinate / this.map.widthNum);
			return new Point(atx, aty);
		}

		public function get map():GD_Map
		{
			return _map;
		}

		/**
		 *释放
		 *
		 */
		override public function release():void
		{
			super.release();
			if (this._view)
			{
				//this._view.removeSign=1;
				if(this._view.mapGrid)
					this._view.mapGrid.release();
				this._view.mapGrid=null;
				this._view.release();
				this._view=null;
			}
		}

		/**
		 *  杂物是否贴在地面  类型为300的为贴在地面的杂物
		 * @return
		 *
		 */
		override public function get isFloor():Boolean
		{
			return this.otherType == 300 ? true : false;
		}

		public function get sundryDur():int
		{
			return _sundryDur;
		}

		public function set sundryDur(value:int):void
		{
			_sundryDur=value;
			if(value<1){
				var wallData:GD_HavenWall;
				for(var i:uint=0; i<GV_Map.instance.mapData.wallsAry.length; i++)
				{
					wallData	=	GV_Map.instance.mapData.wallsAry[i] as GD_HavenWall;
					if(wallData.view.mapGrid.building	==	this.view){
						wallData.view.visible	=	true;
					}
				}
			}
			
			this.touchObserve("life");
			
			
		}

		//****************热感的属性******************
		override public function get currentlife():int
		{
			return this.sundryDur
		}

		override public function get lifeMax():int
		{
			return this.sundryDurMax
		}

		override public function get gvName():String
		{
			return this.sundryName
		}

		override public function addObserverFuncs(observerType:String, obderverObj:*):void
		{
			this.addObserver(observerType, obderverObj);
		}

		override public function removeOberverFuns(observerType:String, obderverObj:*):void
		{
			this.removeObserver(observerType, obderverObj);
		}


		//**********************************

	}
}